package com.requestfactory.wire;

import com.requestfactory.wire.spi.WireSPISkeleton;

public final class WireSkeleton {
	
	private final WireSPISkeleton wireSPISkeleton;
	
	WireSkeleton(WireSPISkeleton wireSPISkeleton) {
		assert wireSPISkeleton != null;
		this.wireSPISkeleton = wireSPISkeleton;
	}

	public void bindService(
			Class<?> serviceInterfaceClass, Object serviceImplementation)
	throws WireSkeletonException {
		if(serviceInterfaceClass == null) {
			throw new IllegalArgumentException(
					"Input argument 'serviceInterfaceClass' cannot be null");
		}
		if(serviceImplementation == null) {
			throw new IllegalArgumentException(
					"Input argument 'serviceImplementation' cannot be null");
		}
		assert serviceInterfaceClass != null;
		assert serviceImplementation != null;
		if(!serviceInterfaceClass.isAssignableFrom(
				serviceImplementation.getClass())) {
			throw new IllegalArgumentException(
					"Verify input arguments, " +
					serviceImplementation.getClass().getName() + 
					" doesn't implement " +
					serviceInterfaceClass.getName());
		}
		wireSPISkeleton.bindService(
				serviceInterfaceClass, serviceImplementation);
	}

}
